package skyinline.swing.jdbc;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridBagLayout;

import javax.swing.JLabel;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class J26_SungJukNewData extends JDialog {

	private static J26_SungJukService sjsrv;
	private final JPanel contentPanel = new JPanel();
	private JTextField name;
	private JTextField kor;
	private JTextField eng;
	private JTextField mat;

	/**
	 * Create the dialog.
	 */
	public J26_SungJukNewData( JFrame p ) {
		super( p );
		sjsrv = new J26_SungJukService();
		setModalityType( ModalityType.DOCUMENT_MODAL );
		setTitle( "새 성적 입력" );
		setBounds(100, 100, 640, 480);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		GridBagLayout gbl_contentPanel = new GridBagLayout();
		gbl_contentPanel.columnWidths = new int[]{150, 60, 35, 0, 0, 0};
		gbl_contentPanel.rowHeights = new int[]{125, 0, 0, 0, 0, 0};
		gbl_contentPanel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		contentPanel.setLayout(gbl_contentPanel);
		{
			JLabel laName = new JLabel("이  름");
			GridBagConstraints gbc_laName = new GridBagConstraints();
			gbc_laName.insets = new Insets(0, 0, 5, 5);
			gbc_laName.gridx = 1;
			gbc_laName.gridy = 1;
			contentPanel.add(laName, gbc_laName);
		}
		{
			name = new JTextField();
			GridBagConstraints gbc_name = new GridBagConstraints();
			gbc_name.gridwidth = 2;
			gbc_name.insets = new Insets(0, 0, 5, 0);
			gbc_name.fill = GridBagConstraints.HORIZONTAL;
			gbc_name.gridx = 3;
			gbc_name.gridy = 1;
			contentPanel.add(name, gbc_name);
			name.setColumns(10);
		}
		{
			JLabel laKor = new JLabel("국  어");
			GridBagConstraints gbc_laKor = new GridBagConstraints();
			gbc_laKor.insets = new Insets(0, 0, 5, 5);
			gbc_laKor.gridx = 1;
			gbc_laKor.gridy = 2;
			contentPanel.add(laKor, gbc_laKor);
		}
		{
			kor = new JTextField();
			GridBagConstraints gbc_kor = new GridBagConstraints();
			gbc_kor.gridwidth = 2;
			gbc_kor.insets = new Insets(0, 0, 5, 0);
			gbc_kor.fill = GridBagConstraints.HORIZONTAL;
			gbc_kor.gridx = 3;
			gbc_kor.gridy = 2;
			contentPanel.add(kor, gbc_kor);
			kor.setColumns(10);
		}
		{
			JLabel laEng = new JLabel("영  어");
			GridBagConstraints gbc_laEng = new GridBagConstraints();
			gbc_laEng.insets = new Insets(0, 0, 5, 5);
			gbc_laEng.gridx = 1;
			gbc_laEng.gridy = 3;
			contentPanel.add(laEng, gbc_laEng);
		}
		{
			eng = new JTextField();
			GridBagConstraints gbc_eng = new GridBagConstraints();
			gbc_eng.gridwidth = 2;
			gbc_eng.insets = new Insets(0, 0, 5, 0);
			gbc_eng.fill = GridBagConstraints.HORIZONTAL;
			gbc_eng.gridx = 3;
			gbc_eng.gridy = 3;
			contentPanel.add(eng, gbc_eng);
			eng.setColumns(10);
		}
		{
			JLabel laMat = new JLabel("수  학");
			GridBagConstraints gbc_laMat = new GridBagConstraints();
			gbc_laMat.insets = new Insets(0, 0, 0, 5);
			gbc_laMat.gridx = 1;
			gbc_laMat.gridy = 4;
			contentPanel.add(laMat, gbc_laMat);
		}
		{
			mat = new JTextField();
			GridBagConstraints gbc_mat = new GridBagConstraints();
			gbc_mat.gridwidth = 2;
			gbc_mat.insets = new Insets(0, 0, 5, 0);
			gbc_mat.fill = GridBagConstraints.HORIZONTAL;
			gbc_mat.gridx = 3;
			gbc_mat.gridy = 4;
			contentPanel.add(mat, gbc_mat);
			mat.setColumns(10);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						if(name.getText().equals("") || kor.getText().equals("") ||
								eng.getText().equals("") || mat.getText().equals("")) {
							JOptionPane.showMessageDialog(null, "누락된 항목이 있습니다~", "오 류 발 생!!",
									JOptionPane.ERROR_MESSAGE);
							return ;
						}
						
						String nameval = name.getText();
						int korval = Integer.parseInt( kor.getText() );
						int engval = Integer.parseInt( eng.getText() );
						int matval = Integer.parseInt( mat.getText() );
						
						J26_SungJukVO sj = new J26_SungJukVO();
						sj.setName( name.getText() );
						sj.setKor( kor.getText() );
						sj.setEng( eng.getText() );
						sj.setMat( mat.getText() );
						sjsrv.computeSungJuk(sj);
						String msg = sj.toString();
						JOptionPane.showMessageDialog(null, msg);
						if ( sjsrv.createSungJuk(sj) ) {
							JOptionPane.showMessageDialog(null, "입력 완료");
						} else { 
							JOptionPane.showMessageDialog(null, "입력 실패");
						}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						name.setText("");
						kor.setText("");
						eng.setText("");
						mat.setText("");
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		setVisible( true );
	}

}
